package com.java1234.web;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java1234.dao.MessageDao;
import com.java1234.util.DbUtil;
import com.java1234.util.ResponseUtil;

import net.sf.json.JSONObject;

public class MessageConfirmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

		DbUtil dbUtil=new DbUtil();
		MessageDao messageDao=new MessageDao();
		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

			String delIds=request.getParameter("delIds");
			String Sid=request.getParameter("id");
			int id=Integer.parseInt(Sid);
			Connection con=null;
			try{
				con=dbUtil.getCon();
				JSONObject result=new JSONObject();
				
				int delNums=0;
				if(id==0){
					delNums=messageDao.messageConfirm(con, delIds);
				}
				if(id==1){
					delNums=messageDao.messageConfirmAll(con);
				}
				if(delNums>0){
					result.put("success", "true");
					result.put("delNums", delNums);
				}else{
					result.put("errorMsg", "立项失败");
				}
				ResponseUtil.write(response, result);
			}catch(Exception e){
				e.printStackTrace();
			}finally{
				try {
					dbUtil.closeCon(con);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
